package com.cuit.xsc.weishare.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


import com.cuit.xsc.weishare.R;
import com.cuit.xsc.weishare.logic.MainService;
import com.cuit.xsc.weishare.logic.Task;
import com.cuit.xsc.weishare.util.ConfigUtil;
import com.cuit.xsc.weishare.util.LogUtil;
import com.tencent.weibo.beans.OAuth;
import com.tencent.weibo.utils.OAuthClient;

public class AuthAct extends BaseActivity
{
	private String type;
	public static OAuth qqOauth;
	public static OAuthClient qqAuth;
	private Button button;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.auth);
		
		type = getIntent().getStringExtra(ConfigUtil.TYPE);
		button = (Button) findViewById(R.id.auth);
		button.setOnClickListener(new OnClickListener()
		{
	
			@Override
			public void onClick(View v)
			{
				showProgress();
				if (type.equals(ConfigUtil.QQW))
				{					
					Task task = new Task(Task.GET_QQ_REQUEST_TOKEN, null);
					MainService.addTask(task);				
				
				}
				
				if (type.equals(ConfigUtil.SINAW))
				{
					Task task = new Task(Task.GET_SINA_REQUEST_TOKEN, null);
					MainService.addTask(task);
				}
			}
		});
		
		LogUtil.d(this, "type="+type);	
	}
	
	
	@Override
	public void refresh(Object... param)
	{
		int flag = ((Integer) param[0]).intValue();
		
		dismissProgress();
		String url = (String) param[1];
		if (url == null || url.equals(""))
		{
			LogUtil.d(this, "Failed");
		}
		else 
		{
			LogUtil.d(this, "Success url="+url);
			Intent intent = new Intent(this,WebViewAct.class);
			intent.putExtra("url", url);
			startActivity(intent);
			finish();
		}
		
		switch (flag)
		{
		case Task.GET_QQ_REQUEST_TOKEN:
			
			
			break;
		case Task.GET_SINA_REQUEST_TOKEN:
			break;

		default:
			break;
		}
		
	}
	
	

}
